//
//  LeftViewController.m
//  绿地管理系统
//
//  Created by rimi on 16/1/18.
//  Copyright © 2016年 hexs. All rights reserved.
//

#import "LeftViewController.h"
#import "LeftDrawerViewModel.h"
#import "XSViewController.h"

@interface LeftViewController () <UITextFieldDelegate>

@property (nonatomic, strong) LeftDrawerViewModel   *viewModel;
@property (nonatomic, strong) UILabel   *keyLabel;
@property (nonatomic, strong) UITextField   *keyTextField;
@property (nonatomic, strong) UILabel   *industryTitleLabel;
@property (nonatomic, strong) UILabel   *industryLabel;
@property (nonatomic, strong) UILabel   *jobTitleLabel;
@property (nonatomic, strong) UILabel   *jobLabel;
@property (nonatomic, strong) UILabel   *provinceTitleLabel;
@property (nonatomic, strong) UILabel   *provinceLabel;
@property (nonatomic, strong) UILabel   *cityTitleLabel;
@property (nonatomic, strong) UILabel   *cityLabel;

@property (nonatomic, strong) UIButton  *searchButton;
@property (nonatomic, strong) UIButton  *resetButton;
@property (nonatomic, strong) UIView    *titleView;
@property (nonatomic, strong) UIImageView   *titleImage;
@property (nonatomic, strong) UIButton      *titleButton;

// KVO
- (void)registerObserver;
- (void)unregisterObserver;

// UI
- (void)initializeAppearance;

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
    
    
    [self initializeAppearance];
}


#pragma mark - private methods
// KVO
- (void)registerObserver
{

}
- (void)unregisterObserver
{

}

- (void)initializeAppearance
{
    self.view.layer.contents = (__bridge id)[UIImage imageNamed:@""].CGImage;
    [self.view addSubview:self.keyLabel];
    [self.view addSubview:self.keyTextField];
    [self.view addSubview:self.industryTitleLabel];
    [self.view addSubview:self.industryLabel];
    [self.view addSubview:self.jobTitleLabel];
    [self.view addSubview:self.jobLabel];
    [self.view addSubview:self.provinceTitleLabel];
    [self.view addSubview:self.provinceLabel];
    [self.view addSubview:self.cityTitleLabel];
    [self.view addSubview:self.cityLabel];
    [self.view addSubview:self.searchButton];
    [self.view addSubview:self.resetButton];
    [self.view addSubview:self.titleView];
    [self.titleView addSubview:self.titleImage];
    [self.titleView addSubview:self.titleButton];
}
- (void)onTitleButton:(UIButton *)sender
{
    XSViewController *drawerVC = (XSViewController *)self.parentViewController;
    [drawerVC closeLeftDrawer];
}
#pragma mark --<UITextFieldDelegate>
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField endEditing:YES];
//    [textField resignFirstResponder];
    return YES;
}

#pragma mark -- getter
- (UILabel *)keyLabel
{
    if (_keyLabel == nil) {
        _keyLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 140, 55, 20)];
            label.text = @"关键字";
            label.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0];
//            label.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
            label.font = [UIFont systemFontOfSize:18];
            label;
        });
    }
    return _keyLabel;
}

- (UITextField *)keyTextField
{
    if (_keyTextField == nil) {
        _keyTextField = ({
            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(80, 140, 190, 30)];
            textField.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
            textField.borderStyle = UITextBorderStyleRoundedRect;
            // 设置是否首字母大写
            textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
            // 设置是否自动纠错
            textField.autocorrectionType = UITextAutocorrectionTypeNo;
            // 清空已输入文字（清空按钮）
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            textField.delegate = self;
            textField;
        });
    }
    return _keyTextField;
}

- (UILabel *)industryTitleLabel
{
    if (_industryTitleLabel == nil) {
        _industryTitleLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 177, 55, 20)];
            label.text = @"行    业";
            label.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0];
            //            label.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
            label.font = [UIFont systemFontOfSize:18];
            label;
        });
    }
    return _industryTitleLabel;
}

- (UILabel *)industryLabel
{
    if (_industryLabel == nil) {
        _industryLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 177, 190, 30)];
            label.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
            label.layer.cornerRadius = 5;
            label.layer.masksToBounds = YES;
            label;
        });
    }
    return _industryLabel;
}

- (UILabel *)jobTitleLabel
{
    if (_jobTitleLabel == nil) {
        _jobTitleLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(16, 215, 55, 20)];
            label.text = @"职    务";
            label.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0];
            //            label.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
            label.font = [UIFont systemFontOfSize:18];
            label;
        });
    }
    return _jobTitleLabel;
}

- (UILabel *)jobLabel
{
    if (_jobLabel == nil) {
        _jobLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 215, 190, 30)];
            label.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
            label.layer.cornerRadius = 5;
            label.layer.masksToBounds = YES;
            label;
        });
    }
    return _jobLabel;
}

- (UILabel *)provinceTitleLabel
{
    if (_provinceTitleLabel == nil) {
        _provinceTitleLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 255, 22, 22)];
            label.text = @"省";
            label.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0];
            //            label.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
            label.font = [UIFont systemFontOfSize:18];
            label;
        });
    }
    return _provinceTitleLabel;
}

- (UILabel *)provinceLabel
{
    if (_provinceLabel == nil) {
        _provinceLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 253, 190, 30)];
            label.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
            label.layer.cornerRadius = 5;
            label.layer.masksToBounds = YES;
            label;
        });
    }
    return _provinceLabel;
}

- (UILabel *)cityTitleLabel
{
    if (_cityTitleLabel == nil) {
        _cityTitleLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 290, 22, 22)];
            label.text = @"市";
            label.textColor = [UIColor colorWithRed:133/255.0 green:133/255.0 blue:133/255.0 alpha:1.0];
            //            label.backgroundColor = [UIColor colorWithRed:218/255.0 green:218/255.0 blue:218/255.0 alpha:1.0];
            label.font = [UIFont systemFontOfSize:18];
            label;
        });
    }
    return _cityTitleLabel;
}
- (UILabel *)cityLabel
{
    if (_cityLabel == nil) {
        _cityLabel = ({
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 290, 190, 30)];
            label.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
            label.layer.cornerRadius = 5;
            label.layer.masksToBounds = YES;
            label;
        });
    }
    return _cityLabel;
}
- (UIButton *)searchButton
{
    if (_searchButton == nil) {
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _searchButton.frame = CGRectMake(5, 340, 130, 30);
        [_searchButton setImage:[UIImage imageNamed:@"搜索按钮_03"] forState:UIControlStateNormal];
    }
    return _searchButton;
}
- (UIButton *)resetButton
{
    if (_resetButton == nil) {
        _resetButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _resetButton.frame = CGRectMake(145, 335, 130, 38);
        [_resetButton setImage:[UIImage imageNamed:@"重置按钮_03"] forState:UIControlStateNormal];
    }
    return _resetButton;
}

- (UIView *)titleView
{
    if (_titleView == nil) {
        _titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 50)];
        _titleView.backgroundColor = [UIColor colorWithRed:39/255.0 green:39/255.0 blue:39/255.0 alpha:1.0];
    }
    return _titleView;
}
- (UIImageView *)titleImage
{
    if (_titleImage == nil) {
        _titleImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的人脉搜索_03"]];
        _titleImage.frame = CGRectMake(10, 12, 125, 20);
    }
    return _titleImage;
}
- (UIButton *)titleButton
{
    if (_titleButton == nil) {
        _titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _titleButton.frame = CGRectMake(220, 12, 60, 26);
        [_titleButton setImage:[UIImage imageNamed:@"取消_03"] forState:UIControlStateNormal];
        [_titleButton addTarget:self action:@selector(onTitleButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _titleButton;
}

@end


















